import { useContext } from 'react';
import { BeanManagerContext } from '../contexts/BeanManagerContext';
import { AppBeanMap } from '../beans';

export function useBeanManager<K extends keyof AppBeanMap>(beanName: K): AppBeanMap[K] {
  const beanManager = useContext(BeanManagerContext);
  if (!beanManager) {
    throw new Error('BeanManager context not found');
  }
  return beanManager.getBean(beanName);
} 